package com.persondemo.videoappliction.ui.movie.presenter;

import android.util.Log;

import com.persondemo.videoappliction.bean.TvMovieBean;
import com.persondemo.videoappliction.bean.VideoBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BaseContract;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.movie.contract.MoiveContract;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/3/21.
 */

public class MoviePresenter extends BasePresenter<MoiveContract.View> implements MoiveContract.presenter {
    BaseApi baseApi;

    @Inject
    public MoviePresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getdetilsdata(String type,String types,String city,String ages,String page) {
     baseApi.getdatas(type,types,city,ages,page).compose(RxSchedulers.applySchedulers())
             .compose(mView.bindToLife())
             .subscribe(new Observer<TvMovieBean>() {
                 @Override
                 public void onSubscribe(@NonNull Disposable d) {

                 }

                 @Override
                 public void onNext(@NonNull TvMovieBean tvMovieBean) {
                          if (Integer.parseInt(page)>1){
                              mView.loaddatamore(tvMovieBean.getData().getDylist());
                          }else {
                              mView.loaddata(tvMovieBean);
                          }


                 }

                 @Override
                 public void onError(@NonNull Throwable e) {
                     Log.e("lidaming",e.toString());
                 }

                 @Override
                 public void onComplete() {

                 }
             });
    }
}
